package com.spc.car.data.domain.project.po;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.spc.car.common.utils.StringUtils;
import com.spc.car.data.entity.project.Project;
import com.spc.car.data.util.PageParam;
import lombok.Data;

import javax.validation.constraints.Pattern;
import java.util.Date;

@Data
public class QueryProjectPO<T> extends PageParam<T> {

    private String projectType;

    /**
     * 项目名称
     */
    private String name;

    /**
     * 项目所在行政区划码
     */
    @Pattern(regexp = "[0-6]{6}", message = "区域编码格式错误")
    private String areaCode;

    /**
     * 项目单位/招标人
     */
    private String tenderee;


    /**
     * 项目行业分类(行业代码门类字母码+2位大类数字码)
     */
    private String industryCode;

    /**资金来源Code*/
    private String fundsSourceCode;


    /**
     * 开始时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:dd")
    private Date beginTime;

    /**
     * 结束时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:dd")
    private Date endTime;

    public Wrapper toWrapper() {
        LambdaQueryWrapper<Project> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.isNotBlank(this.getName()), Project::getName, this.getName())
                .eq(StringUtils.isNotBlank(this.getAreaCode()), Project::getAreaCode, this.getAreaCode())
                .eq(StringUtils.isNotBlank(this.getIndustryCode()), Project::getIndustryCode, this.getIndustryCode())
                .eq(StringUtils.isNotBlank(this.getProjectType()), Project::getProjectType, this.getProjectType())
                .eq(StringUtils.isNotBlank(fundsSourceCode), Project::getFundsSourceCode, fundsSourceCode)
                .like(StringUtils.isNotBlank(tenderee), Project::getTenderee, this.getTenderee())
                .gt(StringUtils.isNotNull(this.getBeginTime()), Project::getCreateTime, this.getBeginTime())
                .lt(StringUtils.isNotNull(this.getEndTime()), Project::getCreateTime, this.getEndTime())
                .orderByDesc(Project::getCreateTime);

        return wrapper;
    }
}
